
from bcat.runnable import Runnable

class ImportService(Runnable):
    def _run(self):
        #TODO:
        return True

class ExportService(Runnable):
    def _run(self):
        #TODO:
        return True




class Object(object):
    pass


class Payment(Object):
    def __init__(self):
        self.__id = 0
        self.__date_time = None
        self.__type = 1 #TODO: enum PayType
        self.__amount = 0.0
        self.__pay_flow_seq = ""
        self.__remark = ""
        self.__buy_order = None
        
    def id(self):
        return self.__id
    def date_time(self):
        return self.__pay_date_time
    def type(self):
        return self.__type
    def amount(self):
        return self.__amount
    def pay_flow_seq(self):
        return self.__pay_flow_seq
    def remark(self):
        return self.__remark
    def buy_order(self):
        return self.__buy_order

    def set_id(self, value):
        self.__id = value
    def set_date_time(self, value):
        self.__pay_date_time = value
    def set_type(self, value):
        self.__type = value
    def set_amount(self, value):
        self.__amount = value
    def set_pay_flow_seq(self, value):
        self.__pay_flow_seq = value
    def set_remark(self, value):
        self.__remark = value
    def set_buy_order(self, value):
        if value != self.__buy_order:
            self.__buy_order = value

class RecvInvoice(Object):
    def __init__(self):
        self.__id = 0
        self.__date_time = None
        self.__no = ""
        self.__file_url = ""
        self.__buy_order = None
        self.__remark = ""


class TakeDelivery(Object):
    def __init__(self):
        self.__id = 0
        self.__date_time = None
        self.__no = ""
        self.__buy_order = None
        self.__remark = ""

class Supplier(Object):
    def __init__(self):
        self.__id = 0
        self.__name = ""
        self.__contact_no = ""
        self.__contact_name = ""
        self.__remark = ""

class BuyOrder(Object):
    def __init__(self, **kwargs):
        self.id = kwargs.get("id", 0)
        self.date_time = kwargs.get("date_time", None)
        self.digest = ""
        self.amount = 0.0
        self.price = 0.0
        self.unit = ""
        self.is_payed = False
        self.is_recv_invoice = False
        self.is_take_delivery = False
        self.remark = ""
        self.supplier = None

    def supplier(self):
        return __supplier

    def payment(self):
        []
        pass
    
    def invoice(self):
        [Invoice()]
        pass

    def delivery(self):
        [Delivery()]
        pass

class PaymentToSupplier(Object):
    def __init__(self):
        self.__id = 0
        self.__supplier = None
        self.__pay_mode = 0 #PayMode
        self.__pay_mode_info = ""
        self.__amount = 0.0
        self.__pay_type = 0 #PayType
        self.__pay_flow_seq = ""
        self.__remark

    def supplier(self):
        return self.__supplier





class BuyOrderImporting(ImportService):
    def __init__(self, file, dest):
        self.__file = file
        self.__dest = dest
        self.__excel = Excel(file)

    def is_order(self, row):
        return True
    def create_order(self, row):
        return [1, 2]

    def is_payment(self, row):
        return False
    def create_payment(self, row):
        return [1, 2]

    def _run(self):
        print("BuyOrderImporting")
        """"
        for row in excel.sheet(name).rows():
            pass
            if is_order(row):
                order = self.create_order(row)
                BuyOrder.insert(order)
            elif is_payment(row):
                payment = self.create_payment(row)
                PaymentToSupplier.insert(payment)
            else:
                pass
        """
        return True

import unittest 
class TestImportExportService(unittest.TestCase):
    def test_main(self):
        excel_path = "./abc.xls"
        db = "mysql://abc"
        self.assertTrue(BuyOrderImporting(excel_path, db).run())
        #BuyOrderExporting(db, new_excel_path).run()

        #SellOrderImporting(excel_path, db).run()
        #SellOrderExporing(db, new_excel_path).run()

        #BuyOrderDeltaImporting(excel_path, db).run()
        #SellOrderDeltaImporting(excel_path, db).run()

